/**
 *@auther: tang
 @Date: 2020-11-12
 *Project: group-booking-shop-manage-system
 */
import React from "react"
import {Modal, Tabs} from 'antd';
import * as Icon from '@ant-design/icons';
import AddAdmin from "./AddAdmin";
import AdminsTable from "./AdminsTable";
import Api from "../../../api";
const { TabPane } = Tabs;
class AdminsManage extends React.Component {
    constructor(props) {
        super(props);
        this.state ={
            tableData:[
            ],
            dataIsLoading:true
        }
        this.tabHome = React.createRef();
    }


    componentWillMount() {
        this.getTableData(10,1);
    }
    getTableData(limit,page){
        this.setState({
            dataIsLoading:true
        })
        Api.getAdminList({limit,page}).then(res=>{

            res.list.map(item=>{
                item.key = item.adm_id+item.adm_logindate
            })
            console.log(res.list);
            this.setState({
                tableData:[...res.list]
            }).then(()=>{
                this.setState({
                    dataIsLoading:false
                })
            })

        }).catch(err=>{
            this.setState({
                dataIsLoading:false
            })
        })
    }
    tabClickHandle(key,e){
        console.log(key)
        console.log(this)
        switch (key){
            case "1":
                this.getTableData();
                break;
            case "2":
                console.log(this.props)
        }
    }
    render() {
        return (
            <div>
                <h2>管理员管理</h2>
                <Tabs defaultActiveKey="1" onTabClick={this.tabClickHandle.bind(this)}>
                    <TabPane
                        tab={
                            <span ref={this.tabHome}>
          <Icon.SwitcherTwoTone />
          管理员列表
        </span>
                        }
                        key="1"
                    >
                        <AdminsTable getTableData={this.getTableData.bind(this)} tableData={ this.state.tableData} dataIsLoading={this.state.dataIsLoading} showModal/>
                    </TabPane>
                    <TabPane
                        tab={
                            <span>
          <Icon.FolderAddTwoTone />
          添加管理员
        </span>
                        }
                        key="2"
                    >
                        <AddAdmin tabHomeNode={this.tabHome}/>
                    </TabPane>
                </Tabs>

            </div>
        )
    }
}

export {AdminsManage as default}
